// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async(event, context) => {
    const wxContext = cloud.getWXContext()
    const {
        OPENID,
        APPID,
        UNIONID
    } = wxContext
    const db = cloud.database()
    const _ = db.command
    const orderCollection = db.collection('order_list')
    try {
        orderList = await orderCollection.where({
            _openid: OPENID
        }).get()

        if (!orderList.data) {
            return {
                code: 1,
                message: '找不到订单'
            }
        }
        orderList = orderList.data
    } catch (e) {
        return {
            code: 1,
            message: '找不到商品'
        }
    }
    return {
        orderList
    }
}